#include "GuiSlots.hpp"
#include "../Item/ItemStack.hpp"
#include "../Item/Item.hpp"

GuiSlots::GuiSlots(int id, int x, int y, ItemStack *itemStack)
{
    m_posX = x;
    m_posY = y;
    m_width = 140;
    m_height = 32;
    m_itemStack = itemStack;
    m_displayString = "x " + itemStack->getItem()->getName();
    state = 0;
    if(!m_texture.loadFromFile("Ressources/Sprites/guiSlots.png"))
    {

    }
    m_sprite.setTexture(m_texture);
    std::stringstream ss;
    ss<<itemStack->getStack();
    m_displayString = ss.str() + m_displayString;
}

GuiSlots::~GuiSlots()
{

}

void GuiSlots::draw(Core*core)
{
    m_sprite.setPosition(m_posX, m_posY);
    if (getState())
    {
        m_sprite.setTextureRect(sf::IntRect(0,m_height,m_width,m_height));
        core->window.draw(m_sprite);
    }
    else if (!getState())
    {
        m_sprite.setTextureRect(sf::IntRect(0,0,m_width,m_height));
        core->window.draw(m_sprite);
    }
    sf::Sprite*spriteItem = m_itemStack->getItem()->getSprite();
    spriteItem->setPosition(m_posX, m_posY);
    core->window.draw(*spriteItem);
    core->window.setView(core->window.getDefaultView());
    core->fontRenderer->printString(m_displayString,m_posX*(core->window.getSize().x/VIEW_WIDTH) + 90, m_posY*(core->window.getSize().y/core->guiView->getSize().y) + 35, sf::Color(0,0,0),24);
    core->window.setView(*core->guiView);
}

ItemStack* GuiSlots::getItemStack()
{
    return m_itemStack;
}


